<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>车辆使用记录</title>
    <!--vue-->
    <script src="/js/vue.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="/css/index.css">
    <!-- 引入组件库 -->
    <script src="/js/index.js"></script>
    <!--axios-->
    <script src="/js/axios.min.js"></script>
</head>
<body>
<div id="app">
    <el-row>
        <el-col :span="5"><el-input v-model="auditid" size="mini" placeholder="请输入审核ID"></el-input></el-col>
        <el-col :span="5"><el-input v-model="carplate" size="mini" placeholder="请输入车辆牌照"></el-input></el-col>
        <el-col :span="5"><el-button type="primary" size="mini" @click="search()" icon="el-icon-search">搜索</el-button></el-col>
        <el-col :span="5"><el-button type="primary" size="mini" @click="flush()" icon="el-icon-search">刷新</el-button></el-col>
    </el-row>
    <el-row>
        <el-table
                :data="tableData"
                style="width: 100%">
            <el-table-column
                    prop="id"
                    label="车辆使用ID">
            </el-table-column>
            <el-table-column
                    prop="cartype"
                    label="车辆类型">
            </el-table-column>
            <el-table-column
                    prop="carplate"
                    label="车辆牌照">
            </el-table-column>
            <el-table-column
                    prop="oilmass"
                    label="剩余油量">
            </el-table-column>
            <el-table-column prop="damagelevel" label="损坏程度">
                <template slot-scope="scope">
                    　　　　　　　　　　<span v-if="scope.row.damagelevel==0">无损坏</span>
                    　　　　　　　　　　<span v-if="scope.row.damagelevel==1">中</span>
                    　　　　　　　　　　<span v-if="scope.row.damagelevel==2">重</span>
                    　　　　　　　　</template>
            </el-table-column>
            <el-table-column
                    prop="starttime"
                    label="借出时间">
            </el-table-column>
            <el-table-column
                    prop="endtime"
                    label="归还时间">
            </el-table-column>
            <el-table-column
                    prop="username"
                    label="借车人">
            </el-table-column>
            <el-table-column
                    prop="auditid"
                    label="审核ID">
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                            type="primary"
                            @click="toEdit(scope.row.id)">详细信息</el-button>
                </template>
            </el-table-column>
        </el-table>
    </el-row>
    <el-row>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[2,3,5,10,100, 200, 300, 400]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>
    </el-row>



    <el-row>
        <!--模态框-->
        <el-dialog title="详情" :visible.sync="editFormVisible">
            <el-form :model="form">
                <el-form-item v-if='show' label="车辆使用ID" :label-width="formLabelWidth">
                    <el-input v-model="form.id" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="借车理由" :label-width="formLabelWidth">
                    <el-input
                            type="textarea"
                            :rows="2"
                            placeholder="请输入内容"
                            v-model="form.usereason"
                            :disabled="true">
                    </el-input>
                </el-form-item>
                <el-form-item label="驳回理由" :label-width="formLabelWidth">
                    <el-input
                            type="textarea"
                            :rows="2"
                            placeholder="请输入内容"
                            v-model="form.reject"
                            :disabled="true">
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="editFormVisible = false">取 消</el-button>
            </div>
        </el-dialog>
    </el-row>
</div>
<script>
    var vue = new Vue({
        el:"#app",
        data:{//数据
            tableData:[],
            currentPage:1,
            pageSize:5,
            total:20,
            auditid:null,
            carplate:null,
            editFormVisible:false,//更新对话框是否显示
            form:{},//添加或者更新form
            formLabelWidth:"120px"
        },
        created:function () {
            this.loadData();
        },
        methods:{//方法
            //加载数据的方法
            loadData:function () {
                _this =this;
                //初始化数据
                axios.get('/car/carusePage', {
                    params: {
                        pageNo:this.currentPage,
                        pageSize:this.pageSize,
                        auditid:this.auditid,
                        carplate:this.carplate
                    }
                }).then(function (response) {
                    // handle success  处理成功，回调的方法
                    //console.log(response);
                    //赋值分页列表
                    _this.tableData = response.data.list;
                    //删除最后一页为空时，调到上一页
                    //alert(_this.tableData.length);
                    if(_this.tableData.length==0&&_this.currentPage!=1){
                        _this.currentPage=_this.currentPage-1;
                        _this.loadData();
                    }
                    //赋值总条数
                    _this.total = response.data.total;
                })
            },
            //每页数量发生变化时
            handleSizeChange:function (v) {
                this.pageSize=v;
                this.loadData();
            },
            //当前页数放生变化是
            handleCurrentChange:function (v) {
                this.currentPage=v;
                this.loadData();
            },
            // 搜索方法
            search:function () {
                this.currentPage=1;
                this.loadData();
            },
            flush:function () {
                this.loadData();
            },
            //打开模态框
            toEdit:function (id) {
                this.form={};
                if (id>0){
                    //请求当前行newsid的数据
                    axios.post('/car/caruseOne?id='+id).then(function (response) {
                        _this.form = response.data.list;
                    })
                }
                this.editFormVisible=true;
            }
        }
    });
</script>
</body>
</html>